package com.easy.service.impl;

import com.easy.bean.Raw_material;
import com.easy.mapper.RawMaterialDao;
import com.easy.service.RawMaterialService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RawMaterialServiceImpl implements RawMaterialService {

    @Autowired
    private RawMaterialDao rawMaterialDao;

    @Override
    public Raw_material add(Raw_material rawMaterial) {
        if (rawMaterial.getIsDeleted() == null) {
            rawMaterial.setIsDeleted((byte)0); // 默认未删除
        }
        rawMaterialDao.add(rawMaterial);
        return rawMaterialDao.one(rawMaterial.getId());
    }

    @Override
    public int del(Integer id) {
        return rawMaterialDao.del(id);
    }

    @Override
    public Raw_material edit(Raw_material rawMaterial) {
        rawMaterialDao.edit(rawMaterial);
        return rawMaterialDao.one(rawMaterial.getId());
    }

    @Override
    public List<Raw_material> all(String name) {
        return rawMaterialDao.all(name);
    }

    @Override
    public Raw_material one(Integer id) {
        return rawMaterialDao.one(id);
    }

    @Override
    public void page(Page page, Raw_material rawMaterial) {
        int count = rawMaterialDao.pageCount(rawMaterial);
        List<Raw_material> data = rawMaterialDao.page(page, rawMaterial);
        page.setCount(count);
        page.setData(data);
    }
}
